package com.lxh.cptp.handler;

import com.lxh.cptp.builder.ImageBuilder;
import com.lxh.cptp.builder.NewsBuilder;
import com.lxh.cptp.builder.TextBuilder;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpTpXmlPackage;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * created by lanxinghua@2dfire.com on 2020/2/23
 */
@Component
public class MsgHandler extends AbstractHandler {

  @Override
  public WxCpXmlOutMessage handle(WxCpTpXmlPackage wxMessage, Map<String, Object> context) {
    //@see XmlMsgType
    // 消息处理
    String content = getContent(wxMessage);
    WxCpXmlOutMessage xmlOutMessage = null;
    switch (content) {
      case "图片": {
        content = "1JwpbLSisNzaUb8dGiR6stmseQcRORha2Md9DeV829-1W_G56F6gjsO5ClJ7isccW";
        xmlOutMessage = new ImageBuilder().build(content, wxMessage);
        break;
      }
      case "图文": {
        xmlOutMessage = new NewsBuilder().build(content, wxMessage);
        break;
      }
      default: {
        xmlOutMessage =  new TextBuilder().build(content, wxMessage);
        break;
      }
    }
    return xmlOutMessage;
  }
}
